package com.blockmeta.bbs.minemodule.activity;

import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blockmeta.bbs.baselibrary.base.adapter.BaseTabViewPagerAdapter;
import com.blockmeta.bbs.baselibrary.widget.ToggleScrollViewPager;
import com.blockmeta.bbs.baselibrary.widget.tab.OnTabSelectListener;
import com.blockmeta.bbs.baselibrary.widget.tab.SlidingTabLayout;
import com.blockmeta.bbs.businesslibrary.arouter.RouterConstant;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.base.BaseActivity;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.R2;
import com.blockmeta.bbs.minemodule.fragment.MyMessageFragment;
import com.blockmeta.bbs.minemodule.fragment.MyNewsMsgFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
@Route(path = RouterPath.MY_MESSAGE_ACTIVITY,extras = RouterConstant.EXTRAL_LOGIN)
public class MyMessageActivity extends BaseActivity implements OnTabSelectListener {

    @BindView(R2.id.tab_layout)
    SlidingTabLayout mTabSwitch;
    @BindView(R2.id.vp_container)
    ToggleScrollViewPager mVpContainer;
    @BindView(R2.id.send_send)
    LinearLayout mSendSend;

    private List<Fragment> mFragments;

    @Autowired(name = Constant.ZERO)
    public String mPageNo;

    @Override
    protected boolean showTitle() {
        return false;
    }

    @Override
    public View setView() {
        return LayoutInflater.from(this).inflate(R.layout.activity_my_message, null);
    }

    @Override
    protected void initialize() {
        super.initialize();
        List<String> title = new ArrayList<>(3);
        title.add("消息推送");
        title.add("互动消息");
        mFragments = new ArrayList<>(4);
        mFragments.add(MyMessageFragment.newInstance("0"));
        mFragments.add(MyNewsMsgFragment.newInstance("2"));
        BaseTabViewPagerAdapter vpAdapter = new BaseTabViewPagerAdapter(getSupportFragmentManager(), mFragments, title);
        mVpContainer.setAdapter(vpAdapter);
        mPageNo = getIntent().getStringExtra(Constant.ZERO);
        mPageNo = TextUtils.isEmpty(mPageNo)?"0":mPageNo;
        mVpContainer.setCurrentItem(Integer.valueOf(mPageNo));
        mTabSwitch.setViewPager(mVpContainer);
        mTabSwitch.setOnTabSelectListener(this);
    }

    @OnClick({R2.id.ll_back, R2.id.send_send})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.ll_back) {
            finish();

        } else if (i == R.id.send_send) {
            ((MyNewsMsgFragment) mFragments.get(1)).showDialog();
        }
    }

    @Override
    public void onTabSelect(int position) {
        if (position == 0) {
            mSendSend.setVisibility(View.GONE);
        }else {
            mSendSend.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onTabReselect(int position) {

    }
}
